package com.miao.controller;

import com.miao.dto.RoleDto;
import com.miao.entity.RoleEntity;
import com.miao.service.RoleService;
import com.miao.util.JSONUtils;
import com.miao.util.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author <a href="https://gitee.com/a-tom-is-cry">Xing</a>
 * @Date 2025/10/2 19:14
 * @Description
 */
@Tag(name = "角色服务")
@RestController
@RequestMapping("role")
@CrossOrigin
public class RoleController {
    @Resource
    private RoleService service;

    @Operation(summary = "角色分页")
    @GetMapping("page")
    @Parameters({
            @Parameter(name = "pageSize", description = "分页限制", required = true),
            @Parameter(name = "currentPage", description = "页码", required = true)
    })
    public Result<Object> page(@RequestParam(required = false) Map<String, Object> params) {
        return service.page(params);
    }


    @DeleteMapping("{id}")
    @Parameter(name = "id",description = "被删除用户id",required = true)
    @Operation(summary = "删除角色")
    public Result<Object> deleteUserById(@PathVariable("id") Long id){
        service.removeById(id);
        return new Result<>();
    }

    @Operation(summary = "新增角色")
    @PostMapping("save")
    public Result<Object> save(@RequestBody RoleDto dto){
        service.save(JSONUtils.objParse(dto, RoleEntity.class));
        return new Result<>();
    }
}
